package com.concerneyes.mine.adapter;

import java.util.ArrayList;
import java.util.List;


import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.concerneyes.R;
import com.concerneyes.mine.TabActivity.OrderView.MyOrderView;

import common.AbsBaseView;

/**
 * Depiction: 商机界面适配器
 * <p>
 * Modify:
 * <p>
 * Author: Kevin Lynn
 * <p>
 * Create Date：2016年1月21日 下午7:52:19
 * <p>
 * 
 * @version 1.0
 * @since 1.0
 */
public class MyOrderAdapter extends PagerAdapter {
	private List<String> titleList;
	private List<AbsBaseView> views;
	private String[] orderStyle;

	public MyOrderAdapter(Context context, List<String> titleList) {
		views = new ArrayList<AbsBaseView>();
		this.titleList = titleList;

		orderStyle = context.getResources().getStringArray(R.array.order_me_style);
		for (int i = 0; i < titleList.size(); i++) {
			MyOrderView child = new MyOrderView(context, orderStyle[i], "buyer", i);
			views.add(child);
		}
	}

	public AbsBaseView getView(int position) {
		return views.get(position);
	}

	@Override
	public int getCount() {
		return titleList != null ? titleList.size() : 0;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(views.get(position));
	}

	@Override
	public int getItemPosition(Object object) {
		return super.getItemPosition(object);
	}

	@Override
	public AbsBaseView instantiateItem(ViewGroup container, int position) {
		container.addView(views.get(position));
		return views.get(position);
	}

	@Override
	public boolean isViewFromObject(View view1, Object view2) {
		return view1 == view2;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return titleList.get(position);
	}

}
